package com.lktx.bbfactory.common.exception;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.lktx.bbfactory.common.IErrorCode;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;

public class BizAsserts {

    public static void fail(String message) {
        throw new BusinessException(message);
    }


    public static void fail(IErrorCode errorCode) {
        throw new BusinessException(errorCode);
    }

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new BusinessException(message);
        }
    }

    public static void notNull(Object obj, String message) {
        isTrue(obj != null, message);
    }

    public static void notBlank(String str, String message) {
        isTrue(StringUtils.isNotBlank(str), message);
    }

    public static void notEmpty(Map<?, ?> map, String message) {
        isTrue(MapUtil.isNotEmpty(map), message);
    }

    public static void notEmpty(Collection<?> collection, String message) {
        isTrue(CollectionUtil.isNotEmpty(collection), message);
    }

    public static void isEquals(Object obj1, Object obj2, String message) {
        isTrue(Objects.equals(obj1, obj2), message);
    }

}
